# Contributor: Ian Douglas Scott <ian@iandouglasscott.com>
# Maintainer: Patrycja Rosa <alpine@ptrcnull.me>
pkgname=wabt
pkgver=1.0.36
pkgrel=0
_wasm_c_api="b6dd1fb658a282c64b029867845bc50ae59e1497"
_picosha2="27fcf6979298949e8a462e16d09a0351c18fcaf2"
pkgdesc="WebAssembly binary toolkit"
arch="all"
url="https://github.com/WebAssembly/wabt"
license="Apache-2.0"
makedepends="cmake samurai"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/WebAssembly/wabt/archive/$pkgver.tar.gz
	wasm-c-api-$_wasm_c_api.tar.gz::https://github.com/WebAssembly/wasm-c-api/archive/$_wasm_c_api.tar.gz
	picosha2-$_picosha2.tar.gz::https://github.com/okdshin/PicoSHA2/archive/$_picosha2.tar.gz
	"
# Tests require vendored dependencies (as git submodules). Should be modified
# to use copies from repository.
options="!check"

# secfixes:
#   1.0.30-r0:
#     - CVE-2022-43280
#     - CVE-2022-43282
#     - CVE-2022-43283

prepare() {
	default_prepare

	rmdir third_party/wasm-c-api
	ln -sfv "$srcdir"/wasm-c-api-$_wasm_c_api third_party/wasm-c-api

	rmdir third_party/picosha2
	ln -sfv "$srcdir"/PicoSHA2-$_picosha2 third_party/picosha2
}

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		local crossopts="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi

	CFLAGS="$CFLAGS -O2" \
	CXXFLAGS="$CXXFLAGS -O2" \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_TESTS=OFF \
		$crossopts

	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
5b8c2b9cc7b96c0964a8c33fd13a3f0fdeb665598d6a55f47264f285f52f646865613b6745c20ebecb50f3358c454aaef6737a895bc64009c4ef06ef6ce14a7e  wabt-1.0.36.tar.gz
5d3eec2184f8b66e2358b85f416afaea172f24155a61c9412a9d9374aa50347cf0ebe940f35727bc8c0ffe287033b967cc97a857feab6aa9e5098458e72b4fd0  wasm-c-api-b6dd1fb658a282c64b029867845bc50ae59e1497.tar.gz
9bf66c70c5828a0b89210d1690078a3d418276e9615170cf5b0a72a28bc37087d075f27c07d525ccbb490102b263527e06516fa41ce6231bc918745abbc85fd9  picosha2-27fcf6979298949e8a462e16d09a0351c18fcaf2.tar.gz
"
